<template>
    <el-date-picker
            v-model="model"
            :type="type"
            @change="changed()"
            :placeholder="placeholder"
             size="small"
            :disabled="disabled"
    ></el-date-picker>
</template>
<script>
    export default {
        name: 'SJdatetime',
        props: ['value', 'type', 'placeholder', 'disabled'],  //type: date, dateTime
        data() {
            return {
                input: '',
                model: this.value,
            }
        },
        created() {
            this.model = this.value
        },
        methods: {
            changed() {
                if (this.type == 'date') {
                    this.dateChanged()
                }else{
                    this.dateTimeChanged()
                }
                this.$emit('input', this.model)
                this.$emit('change', this.model)
            },
            // // date转换
            // dateChanged(){
            //     this.input = this.dateFilterData(this.model)
            // },
            // dateFilterData(input) {
            //     var d = new Date(input);
            //     var year = d.getFullYear();
            //     var month =
            //         d.getMonth() < 9 ? "0" + (d.getMonth() + 1) : "" + (d.getMonth() + 1);
            //     var day = d.getDate() < 10 ? "0" + d.getDate() : "" + d.getDate();
            //     return year + "-" + month + "-" + day;
            // },
            // dateTime转换
            dateTimeChanged() {
                this.input = this.dateFilter(this.model)
            },
            dateFilter(input) {
                let d = new Date(input);
                return d
            },
        },
        watch: {
            value: function () {
                this.model = this.value
            }
        }
    }
</script>